//
//  CollegeHeadView.m
//  Arts1
//
//  Created by lanou on 15/8/29.
//  Copyright (c) 2015年 Arts1. All rights reserved.
//

#import "CollegeHeadView.h"
#import "UIViewAdditions.h"
#import "AllHeader.h"
#import <UIImageView+WebCache.h>

@interface CollegeHeadView ()

@property (nonatomic ,assign) int status;

@end

@implementation CollegeHeadView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
//        _shadowView = [[UIView alloc] initWithFrame:self.bounds];
//        [self addSubview:_shadowView];
        
        UIView *backgroundView = [[UIView alloc] initWithFrame:self.bounds];
        backgroundView.backgroundColor = [UIColor whiteColor];
        [self addSubview:backgroundView];
        [UIView viewWideForShadowColor:backgroundView];
        
        UIView *line1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0 + 64, SCREEN_WIDTH, 0.5)];
        line1.alpha = 0.5;
        line1.backgroundColor = kCustomColor(150, 150, 150, 1);
        [self addSubview:line1];
        
        _iconView = [[UIImageView alloc] initWithFrame:CGRectMake(10 , 13 + 64 , 48 , 48)];
//        _iconView.image = [UIImage imageNamed:@"7.jpeg"];
        _iconView.backgroundColor = kRandomColor;
        _iconView.layer.cornerRadius = 24;
        _iconView.layer.masksToBounds = YES;
        [self addSubview:_iconView];
        
        _collegeName = [[UILabel alloc] initWithFrame:CGRectMake(_iconView.right + 10, 20 + 64, 160 , 18)];
        _collegeName.text = @"中央美术学院";
        _collegeName.font = [UIFont systemFontOfSize:16];
        _collegeName.textColor = kCustomColor(40, 40, 50, 1);
        [self addSubview:_collegeName];
        
        _collegeCate = [[UILabel alloc] initWithFrame:CGRectMake(_iconView.right + 10 , _collegeName.bottom + 2, 160, 15)];
        _collegeCate.text = @"招生人数：200-600";
        _collegeCate.font = [UIFont boldSystemFontOfSize:10];
        _collegeCate.textColor = kCustomColor(150, 150, 150, 1);
        [self addSubview:_collegeCate];
        
        _attentionBTN = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _attentionBTN.frame = CGRectMake(SCREEN_WIDTH - 80, 24 + 64, 70, 28 );
        _attentionBTN.titleLabel.font = [UIFont systemFontOfSize:13];
        _attentionBTN.layer.cornerRadius = 4;
        _attentionBTN.layer.masksToBounds = YES;
        
        _attentionBTN.backgroundColor = [UIColor blackColor];
        [self addSubview:_attentionBTN];
        
        UIView *line2 = [[UIView alloc] initWithFrame:CGRectMake(0, 74 + 64, SCREEN_WIDTH, 0.5)];
        line2.alpha = 0.5;
        line2.backgroundColor = kCustomColor(150, 150, 150, 1);
        [self addSubview:line2];
        
        [self createButtons];
    }
    return self;
}

// 循环创建button---- @"最新动态",@"招生简章",@"成绩查询",@"历年考题"
- (void)createButtons{
    NSArray *arr = @[@"最新动态",@"招生简章",@"成绩查询",@"历年考题"];
    
    for (int i = 0; i < 4; i++) {
        UIButton *btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        btn.frame = CGRectMake(i * SCREEN_WIDTH /4.0 + 17, _iconView.bottom + 18, 60, 30);
        btn.tag = 200 + i;
        btn.titleLabel.font = [UIFont systemFontOfSize:13];
        if (i == 0) {
        [btn setTitleColor:lFONTCOLOR forState:(UIControlStateNormal)];
        } else {
        [btn setTitleColor:sFONTCOLOR forState:(UIControlStateNormal)];
        }
        [btn setTitle:arr[i] forState:(UIControlStateNormal)];
        [btn addTarget:self action:@selector(enterNextView:) forControlEvents:(UIControlEventTouchUpInside)];
        [self addSubview:btn];
    }
    
    for (int i = 1; i < 4; i ++) {
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(i * SCREEN_WIDTH /4.0 , _iconView.bottom + 23 , 0.5, 20)];
        line.backgroundColor = kCustomColor(150, 150, 150, 1);
        line.alpha = 0.5;
        [self addSubview:line];
    }
    
    
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(buttonStatus:) name:@"buttonStatus" object:nil];
    
}

- (void)buttonStatus:(NSNotification *)buttonStatus
{
    //已经关注
//    if (_status) {
    
    NSLog(@"%@",buttonStatus.object);
    _status = [buttonStatus.object intValue];
    
    if (_status) {
        [_attentionBTN setTitle:@"取消关注" forState:(UIControlStateNormal)];
        _status = 0;
    }
    else
    {
        [_attentionBTN setTitle:@"关注" forState:(UIControlStateNormal)];
        _status = 1;
    }
//    }
}

// 重写setter方法，给控件赋值
- (void)setSchool:(SSDetailModel *)school{
    _school = school;
    _collegeName.text = _school.intro;
    [_iconView sd_setImageWithURL:[NSURL URLWithString:_school.headImg]];
}

- (void)enterNextView:(UIButton *)btn{
    NSInteger index = btn.tag - 200;
    [btn setTitleColor:lFONTCOLOR forState:(UIControlStateNormal)];
    for (int i = 0; i < 4; i++) {
        if (index != i ) {
          UIButton *button = (UIButton *)[self viewWithTag:200 + i];
          [button setTitleColor:sFONTCOLOR forState:(UIControlStateNormal)];
        }
    }
    if (_changeviewblock) {
        _changeviewblock(index);
    }
}






/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
